package com.afterglow.aihaigui.controller;

import com.afterglow.aihaigui.entity.ChatRoom;
import com.afterglow.aihaigui.service.ChatService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/chat")
@CrossOrigin
public class ChatController {

    @Resource
    private ChatService chatService;

    /**
     * 和AI对话
     * @param roomId 聊天室ID
     * @param message 包含消息内容的请求体
     * @return AI的回复
     */
    @PostMapping("/{roomId}/send")
    public String doChat(@PathVariable long roomId, @RequestParam String message) {
        return chatService.doChat(roomId, message);
    }

    /**
     * 获取聊天室列表及历史消息
     * @return 聊天室列表
     */
    @GetMapping("/rooms")
    public List<ChatRoom> getHistoryMessages() {
        return chatService.getHistoryMessages();
    }

}
